package magicboard.geometry
{
  import flexunit.framework.TestCase;
  import flexunit.framework.TestSuite;
  
  import magicboard.geometry.Vector;
  
  public class VectorTestCase extends TestCase
  {
    // --------------------------------------------------------------------------------------------	
    public function VectorTestCase(methodName:String) {
   	 super( methodName );
    }

    // --------------------------------------------------------------------------------------------	
    public static function suite():TestSuite {
   			var ts:TestSuite = new TestSuite();
   			
   			ts.addTest( new VectorTestCase( "testDot" ) );
   			ts.addTest( new VectorTestCase( "testAngle0" ) );
   			ts.addTest( new VectorTestCase( "testAngle45" ) );
   			ts.addTest( new VectorTestCase( "testAngle135" ) );
   			ts.addTest( new VectorTestCase( "testAngle315" ) );
   			ts.addTest( new VectorTestCase( "testLength" ) );
   			return ts;
   		}

  
    // --------------------------------------------------------------------------------------------
		/**
		 * Dot( (1,0), (1,0) ) = 1;
		 */
		public function testDot():void {
 			
 			var v1:Vector = new Vector(1,0);
 			var v2:Vector = new Vector(0, 1); 
 			var v3:Vector = new Vector(1,1);

      assertEquals(1, Vector.dot(v1, v1) ); 			
 			
      assertEquals(0, Vector.dot(v1, v2) );
 			
      assertEquals(1, Vector.dot(v1, v3) );
 			
 		}
  		
    // --------------------------------------------------------------------------------------------
		public function testAngle0():void {
 			
 			var v:Vector = new Vector(1,0);
 			
      assertEquals(0, v.angle );
 			
 		}
  		
    // --------------------------------------------------------------------------------------------
		public function testAngle45():void {
 			
 			var v:Vector = new Vector(10,10);
 			
      assertEquals(Math.floor(1/4*Math.PI*1000), Math.floor(v.angle*1000) );
 			
 		}
  		
    // --------------------------------------------------------------------------------------------
		public function testAngle135():void {
 			
 			var v:Vector = new Vector(-10,10);
 			
      assertEquals(Math.floor(3/4*Math.PI*1000), Math.floor(v.angle*1000) );
 			
 		}
  		
    // --------------------------------------------------------------------------------------------
		public function testAngle315():void {
 			
 			var v:Vector = new Vector(10,-10);
 			
      assertEquals(Math.floor(7/4*Math.PI*1000), Math.floor(v.angle*1000) );
 			
 		}
  		
    // --------------------------------------------------------------------------------------------
		/**
		 * Dot( (1,0), (1,0) ) = 1;
		 */
		public function testLength():void {
 			
 			var v1:Vector = new Vector(1,0);
 			var v2:Vector = new Vector(3, 4); 
 			var v3:Vector = new Vector(0,1);

      assertEquals(1, v1.length ); 			
 			
      assertEquals(5, v2.length );
 			
      assertEquals(1, v3.length );
 			
 		}
  		
 	}
}